var _o;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_BundleManager = _o = /* */function (_cc$Component2) {
  function _ctor() {
    var _this5;
    babel_classCallCheck(this, _ctor);
    _this5 = _callSuper(this, _ctor, arguments);
    _this5.resBundle = null;
    _this5.levelsBundle = null;
    _this5.levelsBundles = [];
    return _this5;
  }
  babel_inherits(_ctor, _cc$Component2);
  return babel_createClass(_ctor, [{
    key: "loadBundle",
    value: function loadBundle(e) {
      return new Promise(function (t, n) {
        var _o2 = cc.assetManager.getBundle(e);
        if (_o2) {
          t(_o2);
        } else {
          cc.assetManager.loadBundle(e, cc.AssetManager.Bundle, function (e, _o3) {
            if (e) {
              n();
            } else {
              t(_o3);
            }
          });
        }
      });
    }
  }, {
    key: "loadTxtSync",
    value: function loadTxtSync(e) {
      return this.loadAsset(e, cc.TextAsset);
    }
  }, {
    key: "loadJsonSync",
    value: function loadJsonSync(e) {
      return this.loadAsset(e, cc.JsonAsset);
    }
  }, {
    key: "loadSoundSync",
    value: function loadSoundSync(e) {
      return this.loadAsset(e, cc.AudioClip);
    }
  }, {
    key: "loadSpriteSync",
    value: function loadSpriteSync(e) {
      return this.loadAsset(e, cc.SpriteFrame);
    }
  }, {
    key: "loadPrefabSync",
    value: function loadPrefabSync(e) {
      return this.loadAsset(e, cc.Prefab);
    }
  }, {
    key: "loadAnimSync",
    value: function loadAnimSync(e) {
      return this.loadAsset(e, cc.AnimationClip);
    }
  }, {
    key: "loadAsset",
    value: function loadAsset(e, t) {
      var _this6 = this;
      return new Promise(function (n, _o4) {
        var i = e.split("/");
        var s = i.shift();
        var a = i.join("/");
        _this6.loadBundle(s).then(function (e) {
          e.load(a, t, function (e, t) {
            if (e) {
              _o4(null);
            } else {
              n(t);
            }
          });
        });
      });
    }
  }, {
    key: "loadSpine",
    value: function loadSpine(e) {
      var _this7 = this;
      return new Promise(function (t, n) {
        var _o5 = e.split("/");
        var i = _o5.shift();
        var s = _o5.join("/");
        _this7.loadBundle(i).then(function (e) {
          e.loadDir(s, function (e, _o6) {
            if (e) {
              n(null);
            } else {
              var _e4 = null;
              for (var _t3 = 0; _t3 < _o6.length; _t3++) {
                if (_o6[_t3]._skeletonJson) {
                  _e4 = _o6[_t3];
                  break;
                }
              }
              t(_e4);
            }
          });
        });
      });
    }
  }, {
    key: "loadDir",
    value: function loadDir(e, t) {
      var _this8 = this;
      return new Promise(function (n, _o7) {
        var i = e.split("/");
        var s = i.shift();
        var a = i.join("/");
        _this8.loadBundle(s).then(function (e) {
          e.loadDir(a, function (e, n) {
            t && t(e, n);
          }, function (e, t) {
            if (e) {
              _o7(null);
            } else {
              n(t);
            }
          });
        });
      });
    }
  }], [{
    key: "getInstance",
    value: function getInstance() {
      null == this.instance && (this.instance = new _o());
      return this.instance;
    }
  }]);
}(cc.Component);
def_BundleManager.instance = null;
def_BundleManager = _o = cc__decorate([ccp_ccclass], def_BundleManager);
exports.default = def_BundleManager;